








#include "diskio.h"		
#include "sdcard.h"		

static u32 SD_Buff[SECTOR_SIZE];    





DSTATUS disk_initialize (
	BYTE pdrv				
)
{
    
    extern SD_CardInfo SDCardInfo;
    DSTATUS Status;
    
    Status = SD_Init();

    if (Status == SD_OK)
    {	
        
        Status = SD_GetCardInfo(&SDCardInfo);
    }
    if (Status == SD_OK)
    {
        
        Status = SD_SelectDeselect((u32) (SDCardInfo.RCA << 16));
    }
    if (Status == SD_OK)
    {
        Status = SD_EnableWideBusOperation(SDIO_BusWide_4b);
    }
    
    if (Status == SD_OK)
    { 
        Status = SD_SetDeviceMode(SD_DMA_MODE);


    }	 
    return Status;
}






DSTATUS disk_status (
	BYTE pdrv		
)
{
	return STA_INIT;
}






DRESULT disk_read (
	BYTE pdrv,		
	BYTE *buff,		
	DWORD sector,	
	BYTE count		
)
{
	if(count == 1)
    {
        
        SD_ReadBlock(sector << SECTOR_SHIFT, SD_Buff, SECTOR_SIZE);                 
        memcpy(buff, SD_Buff, SECTOR_SIZE);
	}






    
	return RES_OK;
}






DWORD get_fattime(void)
{
    return ((2013UL-1980) << 25)    
                  | (4UL << 21)     
                  | (7UL << 16)     
                  | (15U << 11)     
                  | (16U << 5)      
                  | (0U >> 1)       
                  ;
}






#if _USE_WRITE
DRESULT disk_write (
	BYTE pdrv,			
	const BYTE *buff,	
	DWORD sector,		
	BYTE count			
)
{
	if(count == 1)
    {
        
        memcpy(SD_Buff, buff, SECTOR_SIZE);                 
        SD_WriteBlock(sector << SECTOR_SHIFT, SD_Buff, SECTOR_SIZE);               
	}







	return RES_OK;
}
#endif






#if _USE_IOCTL
DRESULT disk_ioctl (
	BYTE pdrv,		
	BYTE cmd,		
	void *buff		
)
{
	return RES_OK;
}

#endif



